using System;
using System.Linq;
using System.Reflection;
using System.Text;

namespace MirrorMirror
{
    public static class TypeExtensions {
        public static string Description(this Type type) {
            var builder = new StringBuilder(type.FullName.GetUntil("`"));
            
            if (type.IsGenericType)
                builder.AppendFormat("<{0}>", type.GetGenericArguments().Select(x => x.Description()).Join(","));
            
            return builder.ToString();
        }

        public static string Description(this MethodInfo method)
        {
            var builder = new StringBuilder(method.Name.GetUntil("`"));

            if (method.IsGenericMethod)
                builder.AppendFormat("<{0}>", method.GetGenericArguments().Select(x => x.Description()).Join(","));
            
            builder.Append("(");
            builder.Append(method.GetParameters().Join(",", x => x.ParameterType.Name));
            builder.Append(")");
            return builder.ToString();
        }
    }
}